package com.vdong.restful.controller;


import com.vdong.restful.api.request.CancelOrderRequest;
import com.vdong.restful.api.request.OOrderRequest;
import com.vdong.restful.api.request.OrderRequest;
import com.vdong.restful.api.response.Response;
import com.vdong.restful.service.OrderApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderApiService orderApiService;

    /**
     * 电子面单
     *
     * @param orderRequest
     * @return
     */
    @RequestMapping(value = "/placeOrderService.json", method = RequestMethod.POST)
    public Response saveOrder(@Valid @RequestBody OrderRequest orderRequest, String key) {

        return orderApiService.downOrder(orderRequest, key);
    }

    /**
     * 预约取件
     *
     * @param OOrderRequest
     * @return
     */
    @RequestMapping(value = "/doorTaskService.json", method = RequestMethod.POST)
    public Response saveOOrder(@Valid @RequestBody OOrderRequest OOrderRequest, String key) {

        return orderApiService.noticeOrder(OOrderRequest, key);
    }

    /**
     * 取消订单
     *
     * @param cancelOrderRequest
     * @return
     */
    @RequestMapping(value = "/cancelOrderService.json", method = RequestMethod.POST)
    public Response cancelOrder(@Valid @RequestBody CancelOrderRequest cancelOrderRequest) {
        return orderApiService.cancelOrder(cancelOrderRequest);
    }

}
